package com.everbest.flowable;

public class ResultBean<T> {

    private int code;
    private String msg;
    private T bean;

    public ResultBean<T> set(int code) {
        this.code = code;
        String msg = "";
        switch (code) {
            case 100:
                msg = "成功";
                break;
            case 200:
                msg = "任务完成";
                break;
            case 201:
                msg = "实例删除完成";
                break;
            case 202:
                msg = "流程定义删除完成";
                break;
            case 203:
                msg = "流程定义部署完成";
                break;
            case 204:
                msg = "流程实例启动完成";
                break;
            case 205:
                msg = "任务拾取成功";
                break;
            case 401:
                msg = "任务id为空";
                break;
            case 402:
                msg = "流程实例不存在或不是激活状态";
                break;
            case 403:
                msg = "流程定义的id为空";
                break;
            case 404:
                msg = "任务不存在";
                break;
            case 405:
                msg = "流程定义不存在";
                break;
            case 406:
                msg = "任务为空";
                break;
            case 407:
                msg = "业务id为空";
                break;
            case 408:
                msg = "代理人为空";
                break;
            case 500:
                msg = "流程定义已经存在";
                break;
            case 501:
                msg = "任务无法拾取";
                break;
            case 1001:
                msg = "上传请求异常";
                break;
            case 1002:
                msg = "上传文件保存目录创建异常";
                break;
            case 1003:
                msg = "上传文件异常";
                break;
            case 1004:
                msg = "文件总大小超限";
                break;
            case 1006:
                msg = "上传文件完成";
                break;
            case 999:
                msg = "失败";
                break;
            default:
                msg = "未知";
                break;
        }
        this.msg = msg;
        return this;
    }

    public ResultBean set(int code, String msg) {
        this.code = code;
        this.msg = msg;
        return this;
    }

    public ResultBean<T> set(T bean) {
        this.bean = bean;
        return this;
    }

    public ResultBean<T> setBean(T bean) {
        this.bean = bean;
        return this;
    }

    public ResultBean(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultBean<T> success() {
        this.set(ResultDesc.SUCCESS);
        return this;
    }

    public ResultBean<T> error() {
        this.set(ResultDesc.ERROR);
        return this;
    }

    /**
     * 仅用于判断ResultBean是否返回失败的code为999的结果
     * 
     * @return 结果是否为Error
     */
    public boolean isError() {
        return this.code == ResultDesc.ERROR;
    }

    /**
     * 仅用于判断ResultBean是否返回成功的code为100的结果
     * 
     * @return 结果是否为Success
     */
    public boolean isSuccess() {
        return this.code == ResultDesc.SUCCESS;
    }

    public T getBean() {
        return bean;
    }

    public ResultBean() {}

    @Override
    public String toString() {
        return " code=" + code + ",msg=" + msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

}
